/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.feedback;

import com.apt.bean.FeedBacks;
import com.apt.tag.Connect_DB;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

/**
 *
 * @author Bach
 */
public class GetListFeedBack {

    public static HashMap<Integer, FeedBacks> getListFeeedBack() {
        HashMap<Integer, FeedBacks> listFB = new HashMap<Integer, FeedBacks>();
        PreparedStatement ps = null;
        ResultSet rs = null;
        Connection conn = null;
        String query = "SELECT [Feedback_Id]\n"
                + "      ,[Feedback_Text]\n"
                + "      ,[FeedBacks].[Account_Id]\n"
                + "      ,[Created_Time]\n"
                + "      ,[Feedback_Status]\n"
                + "      ,[User_Name]\n"
                + "  FROM [Matrimony].[dbo].[FeedBacks] ,[Matrimony].[dbo].[Accounts] where Feedback_Status=1 and Accounts.Account_Id=FeedBacks.Account_Id and Account_Role!='admin'";
        try {
            conn = Connect_DB.getConnection();
            if (conn != null) {
                ps = conn.prepareStatement(query);
                rs = ps.executeQuery();
                int key = 1;

                int feedback_Id = 0;
                String feedback_Text = "";
                int account_Id = 0;
                String created_Time = "";
                int feedback_Status = 0;
                String user_Name = null;
                while (rs.next()) {
                    feedback_Id = rs.getInt("Feedback_Id");
                    feedback_Text = rs.getString("Feedback_Text");
                    account_Id = rs.getInt("Account_Id");
                    feedback_Status = rs.getInt("Feedback_Status");
                    created_Time = rs.getString("Created_Time");
                    user_Name = rs.getString("User_Name");
                    FeedBacks fb = new FeedBacks(feedback_Id, feedback_Text, account_Id, created_Time, feedback_Status, user_Name);
                    listFB.put(key, fb);
                    key++;
                }
            } else {
                System.out.println("Connect is null");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Connect_DB.close(rs, null, ps, conn);
        }
        return listFB;
    }
}
